import axios from "axios";
import { defineStore } from "pinia";
import { NewsItem, NewsRes } from "../../types/data";

export default defineStore('newList',{
  state(){
    return {
      list : [] as NewsItem[]
    }
  },
  actions:{
    //获取新闻列表
    async getNews(channelId:number) {
      const {data:{data:{results}}} = await axios.get<NewsRes>('http://geek.itheima.net/v1_0/articles?channel_id='+channelId+'&timestamp='+Date.now())
      this.list = results
      //console.log(results);
      
    }
  }
})
